package com.auxgroup.hr.front.site.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.auxgroup.hr.front.commons.config.BusinessConfig;
import com.auxgroup.hr.front.service.comm.OprdefnService;
import com.auxgroup.hr.front.site.inteceptor.SecurityUserInteceptor;
import com.auxgroup.hr.front.site.inteceptor.SessionGainMethodArgumentResolver;

/**
 * 
* @ClassName: WebSecurityConfig 
* @Description:拦截请求，获取用户信息 
* @author lvliuhao
* @date 2018年1月15日 下午5:04:35  
*
 */
@Configuration
public class WebSecurityConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private BusinessConfig businessConfig;
	
	@Autowired
	private OprdefnService oprdefnService;
	
	/**
	 * 用户是否登录过滤
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new SecurityUserInteceptor(businessConfig,oprdefnService))
		.addPathPatterns("/**").excludePathPatterns("/download/**");
		super.addInterceptors(registry);
	}
	
	/**
	 * 添加静态资源地址
	 */
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射图片保存地址
       registry.addResourceHandler("/emplPhoto/**").addResourceLocations("file:"+businessConfig.getEmplePhotoResourceLocation());
       registry.addResourceHandler("/ftpFile/**").addResourceLocations("file:"+businessConfig.getFtpFileResourceLocation());
    }

	
	/**
	 * 添加自定义注解的使用
	 */
	@Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        super.addArgumentResolvers(argumentResolvers);
        argumentResolvers.add(new SessionGainMethodArgumentResolver());
    }
	
	
	/**
	 * 添加静态视图地址
	 */
	@Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index");
        registry.addRedirectViewController("/index","/index.html");
        super.addViewControllers(registry);
    }
	
}
